package com.rjpacket.supernews.app;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.rjpacket.supernews.app.adapters.ChannelSelectCheckedAdapter;
import com.rjpacket.supernews.app.models.CategoryTitle;
import com.rjpacket.supernews.app.utils.DataContainer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


public class ChannelSelectActivity extends BaseActivity {

    private RecyclerView checkedRecycler;
    private RecyclerView unCheckedRecycler;
    private List<CategoryTitle> titles;
    private List<CategoryTitle> titles1;
    private ChannelSelectCheckedAdapter adapter;
    private ChannelSelectCheckedAdapter adapter1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_channel_select);

        checkedRecycler = (RecyclerView) findViewById(R.id.recycler_checked);
        checkedRecycler.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));

        DataContainer dc = DataContainer.getInstance();
        titles = dc.getCheckedTitles();

        adapter1 = new ChannelSelectCheckedAdapter(this, titles, R.layout.rjp_item_channel_select);
        checkedRecycler.setAdapter(adapter1);

        unCheckedRecycler = (RecyclerView) findViewById(R.id.recycler_unchecked);
        unCheckedRecycler.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));

        titles1 = dc.getUnCheckedTitles();

        adapter = new ChannelSelectCheckedAdapter(this, titles1, R.layout.rjp_item_channel_unselect);
        unCheckedRecycler.setAdapter(adapter);

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.top:
                int position = checkedRecycler.getChildPosition(v);
                CategoryTitle removeTitle = titles.remove(position);
                titles1.add(removeTitle);
                adapter1.notifyDataSetChanged();
                adapter.notifyDataSetChanged();
                break;
            case R.id.down:
                int index = unCheckedRecycler.getChildPosition(v);
                CategoryTitle removeTitle1 = titles1.remove(index);
                titles.add(removeTitle1);
                adapter.notifyDataSetChanged();
                adapter1.notifyDataSetChanged();
                break;
            case R.id.actionbar_back:
                Intent intent = new Intent(this, MainActivity.class);
                startActivity(intent);
                finish();
                break;
        }

//        super.onClick(v);
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.activity_stop, R.anim.activity_right_out);
        finish();
    }
}
